package com.kaifamiao.nio;

import java.nio.ByteBuffer;

public class FlipBufferTest {

    public static void main(String[] args) {

        ByteBuffer buffer = ByteBuffer.allocateDirect(1024);

        System.out.println( buffer );

        buffer.putChar('芳');
        buffer.putChar('儿');
        buffer.putChar(':');
        buffer.putChar('\n');

        System.out.println( buffer );
        // "反转缓冲区"
        buffer.flip(); // limit = position; position = 0; mark = -1;
        System.out.println( buffer );

        buffer.putChar('小');
        buffer.putChar('芳');

        System.out.println( buffer );

        buffer.position(0); // position = newPosition

        System.out.println( buffer.getChar() );
        System.out.println( buffer.getChar() );
        System.out.println( buffer.getChar() );
        System.out.println( buffer.getChar() );

    }

}
